Skip to content

Builds: automation rules v2#12848

Open
humitos wants to merge 55 commits intomainfrom
humitos/webhook-filters-v2
Open

Builds: automation rules v2#12848
humitos wants to merge 55 commits intomainfrom
humitos/webhook-filters-v2

Conversation

@humitos
Copy link
Copy Markdown
Member

@humitos humitos commented Mar 16, 2026

This is the initial proposal to migrate our current VersionAutomationRules and RegexAutomationRules to only one model called AutomationRule as discussed.

I created a basic UI just to be able to use the feature; but we need to work on ext-theme for that. I think it won't be a lot of work, but we need:

  • version_types should be a multi-select field
  • version_match_pattern should be shown/hidden based on another input value
List view Detail view
Screenshot_2026-03-16_17-35-11 Screenshot_2026-03-17_15-57-27

@humitos
Copy link
Copy Markdown
Member Author

humitos commented Mar 17, 2026

@copilot can you create a new PR based on this one to update the test cases matching the code changes?

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

@humitos I've opened a new pull request, #12850, to work on those changes. Once the pull request is ready, I'll request review from you.

Comment thread readthedocs/builds/forms.py Outdated
@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community bot commented Mar 17, 2026

Documentation build overview

📚 dev | 🛠️ Build #32275486 | 📁 Comparing 8d9809f against latest (a3f9dad)

  🔍 Preview build  

No files changed.

return diff.seconds


class VersionAutomationRule(PolymorphicModel, TimeStampedModel):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will delete this model in a following PR and migration. We are not using it anymore.

Copy link
Copy Markdown
Member

@stsewd stsewd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is missing moving the models and forms to the projects app.

Comment thread readthedocs/builds/constants.py
Comment thread readthedocs/builds/forms.py Outdated
Comment thread readthedocs/builds/models.py Outdated
Comment thread readthedocs/builds/models.py Outdated
Comment thread readthedocs/builds/models.py Outdated
Comment on lines +611 to +618
rule_triggered_for_project = True
rule_triggered_for_version = True
rule.run(version)

# We only trigger the first matching rule,
# We only trigger the first matching rule per version
# to avoid triggering multiple builds for the same tag/branches.
break
if rule_triggered_for_version:
break
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to track this in two variables. Since you only want to know if at least one rule matched, you can use a single variable.

Suggested change
rule_triggered_for_project = True
rule_triggered_for_version = True
rule.run(version)
# We only trigger the first matching rule,
# We only trigger the first matching rule per version
# to avoid triggering multiple builds for the same tag/branches.
break
if rule_triggered_for_version:
break
rule_triggered = True
rule.run(version)
# We only trigger the first matching rule per version
# to avoid triggering multiple builds for the same tag/branches.
break

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check all the rules for all the versions. Using only one variable, if the first rule is triggered on the first version, we will be skipping the other versions.

Comment thread readthedocs/oauth/tasks.py Outdated
Copy link
Copy Markdown
Contributor

@agjohnson agjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some needed on the UI side but overall this looks good.

Comment thread readthedocs/projects/models.py
Comment thread readthedocs/builds/constants.py
Comment thread readthedocs/projects/migrations/0159_add_automationrule_v2.py
Comment thread readthedocs/projects/forms.py Outdated
Comment thread readthedocs/projects/forms.py
Comment thread readthedocs/oauth/tasks.py Outdated
Comment on lines +671 to +672
commit_message = self._get_commit_message_from_pull_request_event(project)
labels = self._get_labels_from_pull_request_event(project)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be outside the loop, it's the same for all projects.

Copy link
Copy Markdown
Member Author

@humitos humitos Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼 -- hrm, we use the project.remote_repository.remote_id to get the GHApp installation inside _get_commit_message_from_pull_request_event. I think we need that to be specific for each project.

Comment thread readthedocs/oauth/tasks.py Outdated
Comment thread readthedocs/projects/forms.py
Comment thread readthedocs/projects/models.py Outdated
Comment thread readthedocs/projects/models.py
Comment thread readthedocs/projects/models.py Outdated
)
return False

def match_webhook(self, changed_files=None, commit_message=None, labels=None):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having two methods to check a version moves the responsibility of calling both to the caller, looks like this is already missing one place in api/v2/utils.py (run_version_automation_rules).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is on purpose. Do we want to apply the webhook filters when running rules that apply over versions only? Like activate/deactivate a version; make it as default, etc?

@humitos humitos requested a review from stsewd April 15, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build: webhook filters v2

4 participants